package com.tz.entity;

import javax.persistence.*;
import java.util.List;

/**
 * 产品分类 实体类
 */
@Entity
@Table(name = "SHOP_CATEGORY")
public class Category extends BaseEntity {

    private static final long serialVersionUID = 1L;
    //分类名
    private String name;
    //父类
    private Category parent;
    //子类
    private List<Category> children;
    //备注
    private String remark;
    //层级
    private int level;
    //排序
    private int seq;

    public Category() {
    }

    public Category(String name, Category parent, int level, int seq) {
        this.name = name;
        this.parent = parent;
        this.level = level;
        this.seq = seq;
    }

    public Category(String name, Category parent, List<Category> children) {
        super();
        this.name = name;
        this.parent = parent;
        this.children = children;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne
    @JoinColumn(name = "category_id")
    public Category getParent() {
        return parent;
    }

    public void setParent(Category parent) {
        this.parent = parent;
    }

    //@OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
    @OneToMany(mappedBy = "parent")
    @OrderBy("seq")
    public List<Category> getChildren() {
        return children;
    }

    public void setChildren(List<Category> children) {
        this.children = children;
    }

    @Column(name = "c_remark")
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Column(name = "c_level")
    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    @Column(name = "c_seq")
    public int getSeq() {
        return seq;
    }

    public void setSeq(int seq) {
        this.seq = seq;
    }

    @Override
    public String toString() {
        return "Category{" +
                "name='" + name + '\'' +
                ", remark='" + remark + '\'' +
                ", level=" + level +
                ", seq=" + seq +
                "} " + super.toString();
    }
}
